package com.my.geojson.store;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;

import java.io.IOException;
import java.util.Map;

@Data
@Slf4j
public class PostgisDataStore{
    private static DataStore postgisDataStore = null;
//    private static String dbtype = "postgis";
//    private static String host = "10.137.42.66";
//    private static String port = "5432";
//    private static String database = "admin";
//    private static String schema = "public";
//    private static String username = "admin";
//    private static String password = "123456";

    public static DataStore getInstance() {
        if (postgisDataStore == null) {
            Map<String, String> params = PropertiesUtility.getInstance().getPostgisdbsParams();
//            Map<String, Object> params = new HashMap<String, Object>();
//            params.put(PostgisNGDataStoreFactory.DBTYPE.key, dbtype);
//            params.put(PostgisNGDataStoreFactory.HOST.key, host);
//            params.put(PostgisNGDataStoreFactory.PORT.key, new Integer(port));
//            params.put(PostgisNGDataStoreFactory.DATABASE.key, database);
//            params.put(PostgisNGDataStoreFactory.SCHEMA.key, schema);
//            params.put(PostgisNGDataStoreFactory.USER.key, username);
//            params.put(PostgisNGDataStoreFactory.PASSWD.key, password);
            try {
                postgisDataStore = DataStoreFinder.getDataStore(params);
                log.info("\nPostgisDataStore 初始化geotools中的 Datastore成功\n");
            } catch (IOException e) {
                log.error("\nPostgisDataStore 初始化geotools中的 Datastore失败\n");
                log.error(e.getMessage());
            }
        }
        return postgisDataStore;
    }
}
